//
//  MatePEopleListViewController.m
//  TQY
//
//  Created by 甘世清 on 2024/10/11.
//

#import "MatePEopleListViewController.h"
#import "MatePeopleListTableViewCell.h"
@interface MatePEopleListViewController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation MatePEopleListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.zx_navTitle = SQNSLocalString(@"已加入搭子");
}

- (void)SQ_UIViewForSelfView{
    self.view.backgroundColor = UIColor.whiteColor;
    self.tableView.delegate  = self;
    self.tableView.dataSource = self;
    [self.view  addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.view);
        make.top.equalTo(self.zx_navBar.mas_bottom);
    }];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
     return self.model.users.count;
}
 
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    MatePeopleListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MatePeopleListTableViewCell"];
    if (!cell) {
        cell = [[MatePeopleListTableViewCell alloc] initWithStyle:(UITableViewCellStyleValue1) reuseIdentifier:@"MatePeopleListTableViewCell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    NSDictionary * dic  = [self.model.users objectAtIndex:indexPath.item];
    MateModel * model = [MateModel mj_objectWithKeyValues:dic];
    cell.dic = dic;
    if ([self.model.uid isEqualToString:[UserModel share].userid]) {
        cell.deletedBtn.hidden = NO;
    }
    if ([model.uid isEqualToString:[UserModel share].userid]) {
        cell.deletedBtn.hidden = YES;
    }
    WS(weakSelf);
    [cell.deletedBtn setTouchBlock:^(SQCustomButton * _Nonnull button) {
        [weakSelf SQ_addPeople:dic];
    }];
    return cell;
}
 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return  60;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}

-(void)SQ_addPeople:(NSDictionary*)model{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [dic setObject:[model objectForKey:@"uid"] forKey:@"uid"];
    [dic setObject:@"3" forKey:@"status"];
    [dic setObject:self.model.userid forKey:@"pid"];
    [HttpTool post:@"lug/verify" paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
        [self.jsonArray removeObject:model];
        [self.tableView reloadData];
    } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
        [YJProgressHUD showMsgWithoutView:httpModel.message];
    }];
}


@end
